package com.cc.springboot_test.converter;


import com.cc.springboot_test.utils.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;

@Component
public class TimeStampConverter implements Converter<String, Timestamp> {

    @Override
    public Timestamp convert(String source) {
        if (StringUtils.isEmpty(source) || "null".equalsIgnoreCase(source.trim())) {
            return null;
        }
        return DateUtils.dateToTimestamp(source, DateUtils.DATE_FULL_STR, DateUtils.DATE_MID_STR, DateUtils.DATE_SMALL_STR);
    }
}
